\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mymath}[2014/09/29 Math utils package]


\RequirePackage{amsmath, amsfonts, amssymb, mathrsfs, bbm, pifont, breqn}
\RequirePackage{enumitem}
\RequirePackage{textcomp}
\RequirePackage{ifthen}
\RequirePackage{makeidx}
\RequirePackage{framed}

\newcommand{\theoremboxbegin}{\relax}
\newcommand{\theoremboxend}{\relax}
\DeclareOption{framedtheorems}{
  \renewcommand{\theoremboxbegin}{\begin{minipage}{\textwidth}\begin{framed}}
  \renewcommand{\theoremboxend}{\end{framed}\end{minipage}}
}

\DeclareOption{boxedtheorems}{
  \renewcommand{\theoremboxbegin}{\begin{minipage}{\textwidth}}
  \renewcommand{\theoremboxend}{\end{minipage}}
}
\ProcessOptions\relax

\newcommand{\qedsymbol}{\ensuremath{\blacksquare}}
\newcommand{\qepsymbol}{\ensuremath{\square}}



\newcommand{\mathpolyref}[2][\star]{\ensuremath{(%
  \count255 = 1%
  \loop%
    #1%
  \ifnum\count255 < #2%
  \advance\count255 by 1%
  \repeat%
)}}
\newcounter{mathbreak}
\newcommand{\Resume}{\mathpolyref[\text{\ding{\value{mathbreak}}}]{1}}
\newcommand{\Break}{\addtocounter{mathbreak}{1}\Resume}
\newcommand{\ResumePrevious}{\addtocounter{mathbreak}{-1}\Resume}
\newcommand{\resetmathbreak}{\setcounter{mathbreak}{80}}

\newcommand{\mathref}[2][b]{(\text{\ifthenelse{\equal{#1}{s}}{\ding{7#2}}{\ding{10#2}}})}

% Screw the oversophisticated amsthm!
\newcommand{\theoremstyle}{\bfseries}
\newcommand{\theoremtextstyle}{\sffamily}
\def\optheoremname{\relax}
\newenvironment{theorem}[1][]{%
	\ifx&#1&%
		\def\optheoremname{\relax}%
	\else%
		\index{#1}\def\optheoremname{\leavevmode\newline\mbox{}\hfill\mbox{(\textit{#1})}}%
	\fi%
  \resetmathbreak
  \par\noindent
  \begingroup\theoremstyle\theoremboxbegin
	\noindentТеорема.\space
	\begingroup\theoremtextstyle
}{
  \endgroup
  \optheoremname
  \theoremboxend\endgroup
}

\newcommand{\lemmastyle}{\bfseries}
\newcommand{\lemmatextstyle}{\normalfont\sffamily}
\newenvironment{lemma}[1][]{%
	\ifx&#1&%
		\def\optheoremname{\relax}%
	\else%
		\index{#1}\def\optheoremname{\leavevmode\newline\mbox{}\hfill\mbox{(\textit{#1})}}%
	\fi%
  \par\noindent
  \begingroup\lemmastyle\theoremboxbegin
	\noindent{Лемма.}\space
	\begingroup\lemmatextstyle
}{
  \endgroup\optheoremname
  \theoremboxend\endgroup
}

\newcommand{\consequencesstyle}{\itshape}
\newenvironment{consequences}[1][]{%
	\ifx&#1&%
		\def\optheoremname{\relax}%
	\else%
		\index{#1}\def\optheoremname{(#1)}%
	\fi%
  \begin{enumerate}[label={\consequencesstyle Следствие} \arabic*.\space, align=left]
}{
  \end{enumerate}
}

\newcommand{\definitionstyle}{\bfseries}
\newcommand{\definitiontextstyle}{\normalfont}
\newcommand{\definition}[2][dummy]{%
  \ifthenelse{\equal{#1}{dummy}}{}{\index{#1}}%
	\par\noindent{\definitionstyle Определение.}\space
	{\definitiontextstyle #2}
}

\newcommand{\notestyle}{\itshape}
\newcommand{\note}[1]{
	\par\noindent{\notestyle Замечание.}\space #1
	\par
}

\newcounter{proofsides}

\newenvironment{proof}[0]{%
	\setcounter{proofsides}{0}
	\par\noindent\textit{Доказательство.}\space
}{
	\hfill\qedsymbol\par
}

\newcommand{\GETflag}{\opinsertqep}
\newenvironment{leftproof}[1][]{%
	\par\noindent\textsl{Докажем справа налево.}
	#1
}{%
	\ifnum \value{proofsides}=0
		\hfill\qepsymbol\par
	\fi
	\stepcounter{proofsides}
}
\newenvironment{rightproof}[1][]{%
	\par\noindent\textsl{Докажем слева направо.}
	#1
}{%
	\ifnum \value{proofsides}=0
		\hfill\qepsymbol\par
	\fi
	\stepcounter{proofsides}
}

\newcommand{\natnum}{\mathbbm{N}}
\newcommand{\intnum}{\mathbbm{Z}}
\newcommand{\ratnum}{\mathbbm{Q}}
\newcommand{\realnum}{\mathbbm{R}}
\newcommand{\complexnum}{\mathbbm{C}}
\newcommand{\defset}{\mathscr{D}}

\newcommand{\latin}[1]{\textsl{#1}}
\newcommand{\apst}{\latin{a posteriori}}
\newcommand{\apr}{\latin{a priori}}
\renewcommand{\binom}[2]{\text{\textsl{\Large C}}^{#1}_{#2}}
\renewcommand{\dbinom}[2]{\text{\textsl{\Large C}}^{#1}_{#2}}
\newcommand{\taylor}[3]{\mathrm{P}_#1(#2, #3)}
\newcommand{\Darbu}[0]{S_{\mathcal{D}}}
\newcommand{\darbu}[0]{s_{\mathcal{D}}}
\newcommand{\measure}[1]{\mathrm{m}#1}
\newcommand{\rational}[1]{\mathcal{R}\left(#1\right)}
\newcommand{\Dn}[1]{^{[#1]}}
\def\'#1'{\ensuremath{
  \Dn{#1}
}}

\newcommand{\series}[1]{\mathchoice{\sum_{#1}^{\infty}}{\sum}{\sum}{\sum}}
\newcommand{\assignto}[1][l]{\ensuremath{\ifthenelse{\equal{#1}{s}}{\text{обозн.}}{\text{обозначим за}}}}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\rightto}{\rightrightarrows}
\newcommand{\neigh}{\text{\textsl \Large U}}
\def\pred{\quad\quad}

\newcommand{\TODO}[1]{\textcolor{red}{\framebox{#1}}}

\renewcommand{\[}{\begin{dmath*}[compact]}
\renewcommand{\]}{\end{dmath*}}
\renewcommand{\{}{\ifmmode\lbrace\else\begin{dgroup*}\fi}
\renewcommand{\}}{\ifmmode\rbrace\else\end{dgroup*}\fi}


\endinput
